package com.manshutingyu.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.manshutingyu.common.core.dto.R;
import com.manshutingyu.system.domain.SysDictData;
import com.manshutingyu.system.service.SysDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @Author：yinyuxia
 * @Date：2025/3/31 19:12
 */
@Slf4j
@RestController
@Tag(name = "字典数据")
@RequestMapping("/sys/dict/data")
public class SysDictDataController {
    @Autowired
    private SysDictDataService sysDictDataService;


    @GetMapping(value = "/page")
    public R<IPage<SysDictData>> page(@ParameterObject Page<SysDictData> page, @ParameterObject  SysDictData sysDictData) {
        return R.success(sysDictDataService.page(page, Wrappers.lambdaQuery(sysDictData)));
    }



    @GetMapping(value = "/{id}")
    public R<SysDictData> getById(@PathVariable ("id")Long id) {
        return R.success(sysDictDataService.getById(id));
    }



    @PostMapping
    public R<Integer> save(@RequestBody SysDictData sysDictData) {
        return sysDictDataService.save(sysDictData) ? R.success() : R.error();
    }



    @PutMapping
    public R<Integer> update(@RequestBody SysDictData sysDictData) {
        return sysDictDataService.updateById(sysDictData) ? R.success() : R.error();
    }



    @DeleteMapping(value = "/{ids}")
    public R<Integer> deleteByIds(@Parameter(description = "多个以英文逗号(,)拼接") @PathVariable("ids") Long[] ids) {
        return sysDictDataService.removeBatchByIds(Arrays.asList(ids)) ? R.success() : R.error();
    }
}
